﻿@model EasyBlog.Models.InfoUser

@{
    ViewData["Title"] = "修改密码";
}

<h4>@ViewData["Title"]</h4>
<hr />
<table class="table">
    <tr>
        <td>原密码</td>
        <td><input id="TBOrigin" type="text" class="form-control" maxlength="10" /></td>
        <td><small id="SOrigin" class="text-warning"></small></td>
    </tr>
    <tr>
        <td>新密码</td>
        <td><input id="TBPassword" type="password" class="form-control" maxlength="16" /></td>
        <td><small id="SPassword" class="text-warning"></small></td>
    </tr>
    <tr>
        <td>重输密码</td>
        <td><input id="TBPassword2" type="password" class="form-control" maxlength="16" /></td>
        <td><small id="SPassword2" class="text-warning"></small></td>
    </tr>
    <tr><td colspan="3"><button class="btn btn-primary" onclick="Save()">确认修改</button></td></tr>
</table>

@section Scripts
{
    <script>

    $(function () {

        $("#TBOrigin").change(function () {
            if ($("#TBOrigin").val() == "") {
                $("#SOrigin").html("原密码不能为空");
            }

            CallAjax("@Url.Action("CheckPassword")", {
                pwd: $("#TBOrigin").val()
            }, function (ret) {
                if (ret.message == 0) {
                    $("#TBOrigin").val("");
                    $("#SOrigin").html("原密码不正确");
                }
                else
                    $("#SOrigin").html("");
            });
        });

        $("#TBPassword").change(function () {
            if ($("#TBPassword").val().length<6) {
                $("#SPassword").html("密码长度不能小于6");
            }
            else
                $("#SPassword").html("");
        });

        $("#TBPassword2").change(function () {
            if ($("#TBPassword").val()!=$("#TBPassword2").val()) {
                $("#SPassword2").html("两次输入密码不一样");
            }
            else
                $("#SPassword2").html("");
        });

    });


    function Save() {

        if ($("#TBOrigin").val() == "") {
            ShowMessage("原密码不能为空");
            return;
        }
        if ($("#TBPassword").val().length < 6) {
            ShowMessage("密码长度不能小于6");
            return;
        }
        if ($("#TBPassword").val() != $("#TBPassword2").val()) {
            ShowMessage("两次输入密码不一样");
            return;
        }

        CallAjax("@Url.Action("CheckPassword")", {
            pwd: $("#TBOrigin").val()
        }, function (ret) {

            if (ret.message == 0) {
                $("#TBOrigin").val("");
                $("#SOrigin").html("原密码不正确");
                ShowMessage("原密码不正确");
                return;

            } else {

                $("#SOrigin").html("");

                CallAjax("@Url.Action("ChangePwd")", {password:$("#TBPassword").val()}, function (ret) {
                    ShowMessage(ret.message);
                });
            }
        });
    }
    </script>
}